package com.example.demo.controller;


import com.example.demo.pojo.Student;
import com.example.demo.service.StudentService;
import com.example.demo.vo.Students;
import org.apache.ibatis.javassist.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "queryStudent",method = RequestMethod.POST)
    public List<Student> queryStudent(){
        return studentService.queryStudent();
    }

    @RequestMapping(value = "addStudent",method = RequestMethod.POST)
    public String addStudent(String student_name,int student_number, String student_sex,int student_age,int  class_id){
        if (student_name==""||student_age<=0){
            return "添加学生失败";
        }
        else {
            studentService.addStudent(student_name,student_number,student_sex,student_age,class_id);
            return "添加学生成功";
        }
    }
    @RequestMapping(value = "updateStudent",method = RequestMethod.POST)
    public String updateStudent(Student student){
        if (student==null)
        {
            return "修改学生信息失败";
        }
        else {
            studentService.updateStudent(student);
            return "修改学生信息成功";
        }
    }
    @RequestMapping(value = "deleteStudent",method = RequestMethod.POST)
    public String deleteStudent(Integer id){
        if (id!=null)
        {
            studentService.deleteStudent(id);
            return "删除学生信息成功";
        }
        else {
            return "删除失败";
        }
    }

    @RequestMapping("addStudentCourse")
    public String addStudentCourse(Students students){
        return studentService.add(students);
    }
}
